import time, random
from lib2to3.pgen2 import driver
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from PIL import Image
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.expected_conditions import presence_of_element_located
from selenium.webdriver.support.wait import WebDriverWait
#使用chrome浏览
chrome_browser = webdriver.Chrome()
#启动bbs官网
chrome_browser.get("https://bbs.nga.cn/")
time.sleep(1)
#用xpath元素cilck登录
chrome_browser.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[1]/div/div/div[1]/div[2]/a").click()
time.sleep(1)
#进入内嵌式第一层
iframe = chrome_browser.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div/iframe")
#用chrome运行iframe
chrome_browser.switch_to.frame(iframe)
time.sleep(1)
#进入内嵌式第二层
iframe1 = chrome_browser.find_element(By.XPATH, "/html/body/iframe")
chrome_browser.switch_to.frame(iframe1)
#用chrome运行iframe1
chrome_browser.find_element(By.XPATH, "/html/body/div/div/div[2]/a[1]").click()
time.sleep(1)
#用xpath来click获得验证码
chrome_browser.find_element(By.XPATH, "/html/body/div[1]/div/a[1]").click()
time.sleep(5)
iframe3 = chrome_browser.find_element(By.CSS_SELECTOR,"#tcaptcha_iframe_dy")
time.sleep(5)
chrome_browser.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[6]")